package com.shut.vehicle.controller;

import com.shut.vehicle.controller.result.Result;
import com.shut.vehicle.interceptor.token.Back;
import com.shut.vehicle.interceptor.token.PassToken;
import com.shut.vehicle.pojo.Device;
import com.shut.vehicle.service.DeviceService;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@ResponseBody
@Controller
@RequestMapping(value = "/device_manage")
public class DeviceController {


    @Autowired
    private DeviceService deviceService;

    @Back
    @PostMapping(value = "/device_info")
    public Result addDevice(@RequestBody Device device) {
        deviceService.createDeviceInfo(device);
        return Result.ok();
    }

    @Back
    @DeleteMapping(value = "/device_info")
    public Result deleteDevice(@RequestBody Device device) {
        deviceService.deleteDeviceInfo(device);
        return Result.ok();
    }


    @Back
    @PutMapping(value = "/device_info")
    public Result updateDevice(@RequestBody Device device) {
        deviceService.updateDeviceInfo(device);
        return Result.ok();
    }
    

    @PassToken
    @GetMapping(value = "/device_list")
    public Result listDeviceLikeName(@RequestParam(value = "locationLikeName", required = false) String locationLikeName, @RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        List<Device> deviceList = deviceService.listDeviceSearchLocation(locationLikeName, pageNum, pageSize);
        return Result.okList(deviceList);
    }




}
